package com.jk.service.impl;

import com.github.pagehelper.PageHelper;
import com.jk.bean.*;
import com.jk.mapper.ShorMapper;
import com.jk.service.ShorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShorServiceImpl implements ShorService {
    @Resource
    private ShorMapper shorMapper;


    @Override
    public List<String> getPermission(String userName) {

        List<String> permission = shorMapper.getPermission(userName);
        return permission;
    }

    @Override
    public Staff getUser(String username) {

        return shorMapper.getUser(username);
    }

    @Override
    public String queryUser(String username) {

        return shorMapper.queryUser(username);
    }

    @Override
    public Staff existsPhone(String num) {

        return shorMapper.existsPhone(num);
    }

    @Override
    public Staff heiPhone(String phone_number) {

        return shorMapper.heiPhone(phone_number);
    }

    @Override
    public Staff queryStaff(Staff sd) {

        return shorMapper.queryStaff(sd.getStaffName());
    }

    @Override
    public void goRegister(Staff sd) {
        shorMapper.goRegister(sd);
    }

    @Override
    public SendPage queryRole(Page page) {
        List<Role> list1=shorMapper.queryRole();
        PageHelper.startPage(page.getPage(),page.getRows());
        List<Role> list=shorMapper.queryRole();
        SendPage sendPage = new SendPage(list1.size(),list);
        return sendPage;
    }

    @Override
    public Role updaRole(String id) {
        return shorMapper.updaRole(id);
    }

    @Override
    public void delRole(String ids) {
        shorMapper.delRole(ids);
    }

    @Override
    public void addRole(Role role) {
        if(role.getId()!=null){
            shorMapper.upadteRole(role);
        }
        shorMapper.addRole(role);
    }

    @Override
    public SendPage queryPer(Page page) {
        List<Permission> list1=shorMapper.queryPer();
        PageHelper.startPage(page.getPage(),page.getRows());
        List<Permission> list=shorMapper.queryPer();
        SendPage sendPage = new SendPage(list1.size(),list);
        return sendPage;
    }

    @Override
    public void delPer(String ids) {
        shorMapper.delPer(ids);
    }

    @Override
    public Permission updaPer(String id) {
        return shorMapper.updaPer(id);
    }

    @Override
    public void addPer(Permission per) {
        if(per.getId()!=null){
            shorMapper.updatePer(per);
        }
            shorMapper.addPer(per);
    }

    @Override
    public void delStaff(String id) {
        shorMapper.delStaff(id);
    }
}
